<template>
  <div class="selectstyle">
      <!-- 基本属性 -->
      <el-divider content-position="left">基本属性</el-divider>
    
    <!-- 下拉选择框编辑选项 -->
    <el-form label-width="90px" label-position="left" size="small">
      <el-form-item label="标签文本">
        <el-input v-model="datas.labelText" placeholder="请输入标签文本"></el-input>
      </el-form-item>
      
      <el-form-item label="标签宽度">
        <el-input v-model="datas.labelWidth" placeholder="例如：80px"></el-input>
      </el-form-item>
      
      <el-form-item label="提示文本">
        <el-input v-model="datas.placeholder" placeholder="请输入提示文本"></el-input>
      </el-form-item>
      
      <el-form-item label="宽度">
        <el-input v-model="datas.width" placeholder="例如：100%"></el-input>
      </el-form-item>
      
      <el-form-item label="选项设置">
        <el-col :span="12">
          <el-button type="primary" size="small" @click="addOption">添加选项</el-button>
        </el-col>
        <el-col :span="12">
          <el-button type="danger" size="small" @click="clearOptions">清空选项</el-button>
        </el-col>
        
        <div v-for="(option, index) in datas.options" :key="index" style="display: flex; margin-top: 10px;">
          <el-input v-model="option.label" placeholder="标签" style="margin-right: 5px;"></el-input>
          <el-input v-model="option.value" placeholder="值" style="margin-right: 5px;"></el-input>
          <el-button type="danger" icon="Delete" circle size="small" @click="removeOption(index)"></el-button>
        </div>
      </el-form-item>
      
      <el-form-item label="功能选项">
        <el-checkbox v-model="datas.multiple">多选</el-checkbox>
        <el-checkbox v-model="datas.clearable">可清空</el-checkbox>
        <el-checkbox v-model="datas.collapseTags" v-if="datas.multiple">折叠标签</el-checkbox>
        <el-checkbox v-model="datas.filterable">可搜索</el-checkbox>
        <el-checkbox v-model="datas.allowCreate">允许创建</el-checkbox>
        <el-checkbox v-model="datas.disabled">禁用状态</el-checkbox>
        <el-checkbox v-model="datas.required">必填</el-checkbox>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'selectstyle',
  props: {
    datas: Object,
    'data-type': String,
  },
  methods: {
    addOption() {
      this.datas.options.push({
        label: '新选项',
        value: this.datas.options.length + 1 + ''
      });
    },
    removeOption(index) {
      this.datas.options.splice(index, 1);
    },
    clearOptions() {
      this.datas.options = [];
    }
  }
}
</script>

<style scoped lang="less">
.selectstyle {
  width: 100%;
  box-sizing: border-box;
  
  /* 标题 */
  h2 {
    padding: 24px 16px 24px 0;
    margin-bottom: 15px;
    border-bottom: 1px solid #f2f4f6;
    font-size: 18px;
    font-weight: 600;
    color: #323233;
  }
}
</style> 